import React from 'react'

import {WeaLocaleProvider, WeaTools} from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

import './style'
import ContainerModle from '../../common/containerModle'
import AddExtend from './addExtend'
import SettingExtend from './settingExtend'
import SettingStyleExtend from './settingStyleExtend'
import SettingProxy from './settingProxy'
import ContainerViewExtend from './containerViewExtend'
import ContainerViewProxy from './containerViewProxy'


export default class MenuCommon extends React.Component{

    static defaultProps = {
        javaInterface:{
            find: '/api/portalTsLogin/element/getCommonAbstractImplDataNoUser',
            save: '/api/portalTs/commonAbstractImpl/save',
            update: '/api/portalTs/commonAbstractImpl/update',
            saveOrUpdateItem: '/api/portalTs/commonAbstractImpl/saveOrUpdateItem',
            deleteItem: '/api/portalTs/commonAbstractImpl/deleteItem',
            orderItem: '/api/portalTs/commonAbstractImpl/orderItem',
        }
    }

    onSaveBeforeHandler = (setting={})=>{

        if(this.props.subMenuData){
            setting.title = '二级菜单'
        }else{
            setting.title = '一级菜单'
        }

        setting.modle = '0'
        setting.showType = '0'
        setting.showMenuItem = '0'
        setting.fontSize = 12
        setting.menuItemTBSpacing = 10
        setting.menuItemLRSpacing = 10
        setting.menuItemTBMargin = 6
        setting.menuItemLRMargin = 6
        setting.radius = 4
        setting.menuItemAutoWidth = 0
        setting.menuItemWidth = 90
        setting.autoOpenMenuItemWhenCheckSubMenu = '0'
        setting.backGroundColorGlobal = '#ffffff'
        setting.isBackGroundTransparent = '0'
        setting.backGroundColorMenuItem = '#ffffff'
        setting.fontColor = '#859097'
        setting.fontWeight = '0'
        setting.backGroundColorFirstMenuItemSelected = 'rgb(2, 112, 193)'
        setting.fontColorFirstMenuItemSelected = '#ffffff'
        setting.fontWeightFirstMenuItemSelected = '1'
        setting.backGroundColorOtherMenuItemSelected = 'rgb(2, 112, 193)'
        setting.fontColorOtherMenuItemSelected = '#ffffff'
        setting.fontWeightOtherMenuItemSelected = '1'
    }

    // onLoadAfterHandler = (data,asyncSetState)=>{
    //     if(data && data.items && data.items.length > 0){
    //         for(let i = 0 ; i< data.items.length ;i++){
    //             if(data.items[i].setting.customMenuId){
    //                 WeaTools.callApi('/api/portalTsLogin/utils/findCustomMenu', 'GET', {id:data.items[i].setting.customMenuId}).then((result) => {
    //                     data.items[i].data = result.data
    //                     asyncSetState(data)
    //                 });
    //
    //             }
    //         }
    //     }else{
    //         asyncSetState(data)
    //     }
    //
    // }

    render(){

        return (
            <ContainerModle ecId={`${this && this.props && this.props.ecId || ''}_ContainerModle@gz2fhj`} {...this.props} {...(this.props.location ? this.props.location.query :{})} ContainerViewProxy={ContainerViewProxy} SettingProxy={SettingProxy} onSaveBeforeHandler={this.onSaveBeforeHandler} AddExtend={AddExtend} SettingExtend={SettingExtend} SettingStyleExtend={SettingStyleExtend} ContainerViewExtend={ContainerViewExtend}>
            </ContainerModle>
        )
    }
}